package com.lange.autocode.customDict;

import cn.net.autocode.core.bean.ResultT;
import cn.net.autocode.core.utils.TreeUtils;
import cn.net.autocode.core.utils.UserThreadLocalUtils;
import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.platform.customDict.CustomDict;
import cn.net.autocode.platform.customDict.CustomDictAnnotation;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;

@Component
@CustomDictAnnotation("sysDepart")
public class SysDepartDict implements CustomDict {

    private final Dao dao;

    public SysDepartDict(Dao dao) {
        this.dao = dao;
    }

    @Override
    public ResultT query(JSONObject param) {
        JSONArray array = dao.queryJSONArray("select id value,dept label,id,parent_id from sys_departments where org_code=?", UserThreadLocalUtils.getOrgCode());
        return ResultT.success(TreeUtils.commonTree(array));
    }
}
